home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: bath.ac.uk!bsmail!talisker!nathan
- From: nathan@pact.srf.ac.uk (Nathan Sidwell)
- Subject: Re: 16-bit memset?
- Message-ID: <Dou51s.90p@uns.bris.ac.uk>
- Sender: usenet@uns.bris.ac.uk (Usenet news owner)
- Nntp-Posting-Host: talisker.pact.srf.ac.uk
- Organization: Inmos
- X-Newsreader: TIN [version 1.2 PL2]
- References: <joules-1803962243060001@badboy.mit.edu> <4ill6r$qnm@nntp.interaccess.com> <DoJABC.Hy7@iquest.net>
- Date: Mon, 25 Mar 1996 18:08:16 GMT
-
- Doug Miller (dlmiller@iquest.net) wrote:
- : +Julian Orbanes wrote:
- : +>I am looking quick way to set a series of 16-bit values to one value.
- : +>
- : +>Analagous to how memset set works with 8-bit values. (For graphics
- : +>purposes).
-
- : char *bigstuff;
- : . .
- : /* assuming that: */
- : /* 1) you have allocated storage for bigstuff */
- : /* 2) it is a null-terminated string of the desired FINAL length */
- I don't understand this assumption, strncpy copies until either the number
- of characters has been copied OR a NUL char has been copied.
- : /* 3) you have loaded the value you wish to propagate into the first 2 bytes */
-
- : strncpy (bigstuff + 2, bigstuff, (strlen (bigstuff) - 2));
- ^^^^^^ this relies on bugstuff already
- being initialized!
-
- BUT more importantly, the src and dest locations of all the str* functions
- must not overlap -- if they do, it's undefined behaviour.
-
- One way to do what Julian wanted is to do something like
- WARNING untested C code off the top of my head
- void init16(Int16 *buffer, size_t num, Int16 val)
- {
- size_t count;
-
- *buffer = val;
- for(count = 1; count << 1 <= num; count <<= 1)
- memcpy(&buffer[count], buffer, count * sizeof(Int16));
- if(count != num)
- memcpy(&buffer[count], buffer, (num - count) * sizeof(Int16));
- }
-
- nathan
-
- --
- Nathan Sidwell Holder of the Xmris home page
- Chameleon Architecture Group at SGS-Thomson, formerly Inmos
- http://www.pact.srf.ac.uk/~nathan/ Tel 0117 9707182
- nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
-